﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace Utils
{
    public class MyRelayCommand : ICommand
    {
        #region Fields
            private Action      _handler;
            private bool        _isEnabled;
        #endregion

        #region Properties
            public MyRelayCommand(Action handler)
            {
                _handler = handler;
            }
            public bool IsEnabled
            {
                get { return _isEnabled; }
                set
                {
                    if (value != _isEnabled)
                    {
                        _isEnabled = value;
                        if (CanExecuteChanged != null)
                        {
                            CanExecuteChanged(this, EventArgs.Empty);
                        }
                    }
                }
            }
            public bool CanExecute(object parameter)
            {
                return IsEnabled;
            }
           
            public event EventHandler CanExecuteChanged;

            public void Execute(object parameter)
            {
                _handler();
            }
        #endregion
    }
}
